package films;

import java.util.HashMap;
import java.io.Serializable;

/**
 * This class represents a films colecction in terms of a (title, film) mapping.
 * @author Antiman Nehuen, Jócano Ignacio.
 *
 */
public class FilmsCollection implements Serializable{

	private HashMap<String, Film> films;
	
	public FilmsCollection(){
		films = new HashMap<String, Film>();
	}
	
	/**
	 * Returns an iterable object of the films contained in this collection.
	 * It is advisable not to modify the collection while iterating or vice-versa. 
	 * @return an iterable object of the films contained in this collection.
	 */
	public Iterable<Film> films(){
		return films.values();
	}
	
	/**
	 * Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
	 * @param title
	 * @return the value to which the specified key is mapped, or null if this map contains no mapping for the key.
	 */
	public Film get(String title){
		return films.get(title);
	}
	
	/**
	 * Adds a film to the collection. 
	 * @param f a film to put in the collection.
	 * @return the previous film associated with the title of f, or null if there was no mapping for it. 
	 */
	public Film put(Film f){
		return films.put(f.getTitle(), f);
	}
	
	/**
	 * Removes the film for the specified title from this map if present.
	 * @param title of the film to be removed.
	 * @return the previous film associated with title, or null if there was no mapping for title. 
	 */
	public Film remove(String title){
		return films.remove(title);
	}
	
	public int size(){
		return films.size();
	}
}
